/**
 * Copyright (C) 2014
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package psn.shan.xml.enhancedvalidator.rules.comparator;

import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;




/**
 * AbstractComparator <br />
 *
 * Class or Interface Description 
 * 
 * @author Shan
 * 
 */
@Accessors(prefix = "m")
@Slf4j
public abstract class AbstractComparator<T> {
	
	protected T mOperandOne;
	
	protected T mOperandTwo;
	
	@Setter
	protected int mComparand;
	
	@Setter
	protected OperatorType mOperatorType;

	public abstract void setOperandOne(String aOperandOne) throws Exception;

	public abstract void setOperandTwo(String aOperandTwo) throws Exception;
	
	protected abstract int computeDifference();
	
	public boolean evaluate() {
		int lDifference = computeDifference();
		log.debug("Operand One is " + mOperandOne);
		log.debug("Operand Two is " + mOperandTwo);
		log.debug("Difference is " + lDifference);
		log.debug("Operator is " + mOperatorType);
		boolean lResult = false;
		switch (mOperatorType) {
			case EQUALS_TO:
				if (mComparand == lDifference) {
					lResult = true;
				}
				break;
			case NOT_EQUALS_TO:
				if (mComparand != lDifference) {
					lResult = true;
				}
				break;
			case GREATER_THAN:
				if (mComparand > lDifference) {
					lResult = true;
				}
				break;
			case lESS_THAN:
				if (mComparand < lDifference) {
					lResult = true;
				}
				break;
			default:
				lResult = false;
		}
		return lResult;
	}
}
